package TeacherEvaluation.com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import TeacherEvaluation.com.dao.stu_assessDao;
import TeacherEvaluation.com.dao.studentDao;
import TeacherEvaluation.com.entity.Assess;

@Service
public class stu_assessService {
	@Autowired
	stu_assessDao stu_assessDao;	
	
	
	public int insertAss(Assess assess) {
		int i = stu_assessDao.selectAssByClCo(assess);
		if (i>0) {
			return 0;
		}else {
			return stu_assessDao.insertAss(assess);
		}
	};
	
	public List<Assess> selectAss(){
		return stu_assessDao.selectAss();
	};
	
	public int deleteAss(int as_id) {
		if (stu_assessDao.deleteAss(as_id)>0) {
			return 1;
		}else {
			return 0;
		}
	};
	
	public int updateAss(Assess assess) {
		int i = stu_assessDao.selectAssByClCo(assess);
		if (i>0) {
			return 0;
		}else {
			return stu_assessDao.updateAss(assess);
		}
	};
	
	public List<Assess> selectAssByStu(int stu_id){
		return stu_assessDao.selectAssByStu(stu_id);
	}

	public List<Assess> selectAssByCondition(String className, String select_type) {
		List<Assess> assess=null;
		//根据老师查询授课信息
		if(select_type==null) {
			return selectAss();
		}else {
			if(select_type.equals("0")) {
				assess = stu_assessDao.selectAssByTeacher(className);
				return assess;
				
			}else if(select_type.equals("1")) {
				assess = stu_assessDao.selectAssByCourse(className);
				return assess;
			}else if(select_type.equals("2")) {
				 assess = stu_assessDao.selectAssByClass(className);
				return assess;
			}else {
				return null;
			}
			
		}
	};
}
